// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <memory>
#include <string>
#include <vector>

#include <nebula/io/interfaces.h>
#include <nebula/types/type_fwd.h>

namespace nebula {
    namespace io {
        class MemoryMappedFile;

        TURBO_EXPORT
        void AssertFileContents(const std::string &path, const std::string &contents);

        TURBO_EXPORT bool FileExists(const std::string &path);

        TURBO_EXPORT turbo::Status PurgeLocalFileFromOsCache(const std::string &path);

        TURBO_EXPORT
        turbo::Status ZeroMemoryMap(MemoryMappedFile *file);

        class TURBO_EXPORT MemoryMapFixture {
        public:
            void TearDown();

            void CreateFile(const std::string &path, int64_t size);

            turbo::Result<std::shared_ptr<MemoryMappedFile> > InitMemoryMap(int64_t size,
                                                                            const std::string &path);

            void AppendFile(const std::string &path);

        private:
            std::vector<std::string> tmp_files_;
        };

        class TURBO_EXPORT TrackedRandomAccessFile : public io::RandomAccessFile {
        public:
            virtual int64_t num_reads() const = 0;

            virtual int64_t bytes_read() const = 0;

            virtual const std::vector<io::ReadRange> &get_read_ranges() const = 0;

            static std::unique_ptr<TrackedRandomAccessFile> create(io::RandomAccessFile *target);
        };
    } // namespace io
} // namespace nebula
